{extend name="Public:content"}
{block name="button"}
<!--工具栏 start-->
<div class="row">
    <form name="user_form" action="{:url('Admin/Product/listOrders')}" method="post" id="user_form">
        <div class="col-sm-12 m-b-xs">
            <button class="btn btn-white btn-sm" type="button"  onClick="$.Oa.reload()"><i class="fa fa-refresh"></i> 刷新</button>
            <a class="btn btn-primary btn-sm"  title="添加权限" onclick="user_index.add()" ><i class="fa fa-plus"></i> 添加用户</a>
        </div>
    </form>
</div>
<!--工具栏 end-->
{/block}
{block name="content"}
<div class="table-responsive" style="overflow-x:initial">
    <table id="auth_table" ></table>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    window.user_index = {
        //定义工具栏
        //toolbar: "#user_index_toolbar",
        add: function(){ //添加
            parent.layer.open({
                type: 2,
                title: '{$title} > 添加',
                shadeClose: false,
                shade: 0.8,
                maxmin: false, //开启最大化最小化按钮
                area: ['960px', '650px'],
                content: '{:url("$classuri/add")}?iframe='+window.name,
                yes: function (index, layero){},
                end: function (){}
            });
        },
        edit: function(id){ //编辑
            parent.layer.open({
                type: 2,
                title: '{$title} > 编辑',
                shadeClose: false,
                shade: 0.8,
                maxmin: false, //开启最大化最小化按钮
                area: ['960px', '650px'],
                content: '{:url("$classuri/edit")}?id='+id+'&iframe='+window.name,
                yes: function (index, layero){},
                end: function (){}
            });
        },
        apply:function(id){ //授权
            parent.layer.open({
                type: 2,
                title: '{$title} > 授权',
                shadeClose: false,
                shade: 0.8,
                maxmin: false, //开启最大化最小化按钮
                area: ['960px', '650px'],
                content: '{:url("$classuri/auth")}?id='+id+'&iframe='+window.name,
                yes: function (index, layero){},
                end: function (){}
            });
        },
        //修改密码
        pass: function(id){
            parent.layer.open({
                type: 2,
                title: '{$title} > 编辑',
                shadeClose: false,
                shade: 0.8,
                maxmin: false, //开启最大化最小化按钮
                area: ['960px', '650px'],
                content: '{:url("$classuri/pass")}?id='+id+'&iframe='+window.name,
                yes: function (index, layero){},
                end: function (){}
            });

        },
        //删除操作
        del: function(){
            var ids = $.map($("#auth_table").bootstrapTable('getSelections'),function(row){
                return row.id;
            })
            if(ids.length == 0){
                layer.msg("请先选择要删除的记录!");
                return false;
            }
            if(ids.length > 1){
                layer.msg("只能选择一条记录!");
                return false;
            }
            layer.confirm('确认要删除吗？',function(){
                $.post('{:url("$classuri/del")}',{'id':ids[0],'field':'delete'},function(data){
                    if(200 == data.code){
                        //删除该行
                        $("#auth_table").bootstrapTable('remove',{field:'id',values:ids});
                    }
                    layer.msg(data.msg);
                })
            })
        },
        //操作格式化
        opert: function(value,row){
            var rst = '';
            var edit_auth = '{:auth("$classuri/edit")}';
            var apply_auth = '{:auth("$classuri/apply")}';
            var status_auth = '{:auth("$classuri/status")}';
            var del_auth = '{:auth("$classuri/del")}';
            var pass_auth = '{:auth("$classuri/pass")}';
            if(edit_auth) rst += '<a onclick="user_index.edit('+row.id+')" class="btn btn-white btn-xs">编辑</a> ';
            if(apply_auth) rst += '<a onclick="user_index.apply('+row.id+')" class="btn btn-white btn-xs">授权</a> ';
            if(pass_auth){
                rst += '<a onClick="user_index.pass('+row.id+')" class="btn btn-outline btn-xs btn-white" title="密码" >密码</a> ';
            }
            if(row.status == 1 && status_auth) {
                rst += '<a onclick="$.Oa.status(this,\'string\')" data-url="{:url(\"$classuri/status\")}" data-id="'+row.id+'" data-value="2" class="btn btn-white btn-xs">禁用</a> ';
            }else if(status_auth){
                rst += '<a onclick="$.Oa.status(this,\'string\')" data-url="{:url(\"$classuri/status\")}" data-id="'+row.id+'" data-value="1" class="btn btn-white btn-xs">启用</a> ';
            }
            if(del_auth){
                rst += '<a onClick="$.Oa.delete(this)" data-href="{:url(\"$classuri/del\")}" data-id="'+row.id+'" class="btn btn-outline btn-xs btn-danger" title="删除" >删除</a>';
            }
            return rst;
        }
    }
    $('#auth_table').bootstrapTable({
        method: 'post',
        contentType: "application/x-www-form-urlencoded",
        url:"{:url(\"$classuri/index\")}",
        pageNumber: 1, //初始化加载第一页，默认第一页
        showRefresh: false,
        pagination:true,//是否分页
        sidePagination:'server',//指定服务器端分页
        queryParamsType : "",
        queryParams: function(params){
            return {limit:params.pageSize,page:params.pageNumber,order:params.sortOrder};
        },//参数
        pageSize:10,//单页记录数
        pageList:[10,20,30,40],//分页步进值
        // responseHandler:responseHandler,//请求数据成功后，渲染表格前的方法
        columns :[
            {checkbox:true,width: 20},
            {field:'id',title:'ID',width: 20},
            {field:'username',title:'用户名',width: 80},
            {field:'phone',title:'手机号',width: 150},
//            {field:'mail',title:'电子邮箱',width: 150},
            {field:'quanxian',title:'权限',width: 150},
            {field:'login_at',title:'最后登录',width: 150},
            {field:'status_str',title:'状态',width: 150,formatter:function(value,row){
                    return  row.status == 1 ? '<span class="label label-primary">启用</span>' : '<span class="label label-danger">禁用</span>';
                }},
            {field:'action',title:'操作',width: 200,formatter:user_index.opert},
        ]
    })
</script>
{/block}s